<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>查看服务请求</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<link href="<?php echo base_url()?>media/css/style.css" type="text/css" rel="stylesheet"/>
<link href="<?php echo base_url()?>media/css/jquery-ui-1.8.6.custom.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript" src="<?php echo base_url()?>media/js/jquery/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>media/js/jquery/jquery-ui-1.8.6.custom.min.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>media/js/swfupload/swfupload.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>media/js/swfupload/swfupload.queue.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>media/js/swfupload/fileprogress.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>media/js/swfupload/handlers.js"></script>
</head>
<body>
<div class="form_div"  id="NewRequestFormDiv">
	<h5>SJ<?=sprintf("%08d", $eventId)?>:<?=htmlspecialchars($event['event_title'])?></h5>
	<div class="form_block black_border">
		<div class="input_item margin_r_160">
			<label>事件号</label>
			<input style="width:120px;" type="text" name= "incidentId" value="SJ<?=printf("%08d", $eventId)?>" readonly/>
		</div>
		<div class="select_item">
			<label>请求类型</label>
			<select name="requestType" onchange="this.selectedIndex=1" <?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'"; else echo "readonly";?>>
				<?php foreach($event_type_list as $row):?>
                <option value="<?php echo $row['option_id'];?>" <?php if($row['option_id']==$event['event_type']){echo "selected";}?>><?php echo $row['option_name'];?></option>
                <?php endforeach;?>
			</select>
		</div>
		<div class="select_item margin_r_160">
			<label>紧急程度</label>
			<select name="event_emergency" <?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'"; else echo "readonly";?>>
				<?php foreach($event_emergency_list  as $code=>$name):?>
                <option value="<?php echo $code;?>" <?php if($code==$event['event_emergency']){echo "selected";}?>><?php echo $name;?></option>
                <?php endforeach;?>
			</select>
		</div>
		<div class="select_item">
			<label>影响范围</label>
			<select name="requestType" <?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'"; else echo "readonly";?>>
				<?php foreach($event_influencearea_list as $row):?>
                        <option value="<?php echo $row['option_id'];?>" <?php if($row['option_id']==$event['event_influencearea']){echo "selected";}?>><?php echo $row['option_name'];?></option>
                        <?php endforeach;?>
			</select>
		</div>
		<div class="select_item margin_r_160">
			<label>类别</label>
			<select name="event_category" id="event_category" <?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'"; else echo "readonly";?>>
				<?php foreach($event_cat_list as $row):?>
                        <option value="<?php echo $row['option_id'];?>" <?php if($row['option_id']==$event['event_category']){echo "selected";}?>><?php echo $row['option_name'];?></option>
                        <?php endforeach;?>
			</select>
		</div>
		<div class="select_item">
			<label>子类</label>
			<select name="event_subclass" id="event_subclass" <?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'"; else echo "readonly";?>>
				<?php foreach($event_subclass as $row):?>
                        <option value="<?php echo $row['option_id'];?>" <?php if($row['option_id']==$event['event_subclass']){echo "selected";}?>><?php echo $row['option_name'];?></option>
                        <?php endforeach;?>
			</select>
		</div>
	<div class="clear_both"></div>
	</div>
	<div class="form_block no_top_bborder">
		<div class="input_item input_item_width500" id="incident_title_input_item">
			<label>主题</label>
			<input type="text" name= "incidentId" value="<?php echo htmlspecialchars($event['event_title']);?>" <?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'"; else echo "readonly";?>/>
		</div>
		<div class="textarea_item" >
			<label>描述</label>
			<textarea name="event_desc" <?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE']) echo "disabled='true'"; else echo "readonly";?>><?php echo htmlspecialchars($event['event_desc']);?></textarea>
		</div>
		<div class="clear_both"></div>

		<div id="old_uploaded_file_info" class="uploaded_file_info" style="padding-left:80px;clear:both;<?php if (!empty($event_attachments)): ?>height:40px;<?php endif;?>">
			<?php if (!empty($event_attachments)): ?>
			<?php foreach ($event_attachments as $r): ?>
			<?php if($r['attachment_isreply']==2): ?>
			<div class="file_info">
				<a href="<?=base_url()?><?=$r['attachment_path']?>"><?php echo $r['attachment_name']?></a>
			</div>
			<?php endif;?>
			<?php endforeach; ?>
			<?php endif; ?>
		</div>
		<div class="clear_both"></div>
	</div>
	<div class="clear_both"></div>
	<div class="form_block black_border margin_t_b_5">
		<div class="textarea_item" >
			<label>解决办法</label>
			<textarea name="event_workrecord" readonly><?php if(!empty($event['event_solution'])): echo $event['event_solution']; else:?>事件处理中,暂未提供解决方案<?php endif;?></textarea>
		</div>
		<div class="clear_both"></div>
		<div id="uploaded_file_info2"  class="uploaded_file_info" style="padding-left:80px;clear:both;">
				<?php if (count($event_attachments)>0 && ($event['event_status'] == events_config::$event_status['EVENT_STATUS_SOLUTION'] || $event['event_status'] == events_config::$event_status['EVENT_STATUS_CLOSE'])): ?>
	            <?php foreach($event_attachments as $row): ?>
				<?php if($row['attachment_isreply']==1): ?>
	            <div class="file_info"><a href="<?php echo base_url().$row['attachment_path'];?>"><?php echo $row['attachment_name'];?></a><!--span class='del_attach' aid='<?php echo $row['attachment_id'];?>'>X</span--></div>
				<?php endif; ?>
	            <?php endforeach; ?>
				<?php endif; ?>
		</div>
		<div class="clear_both"></div>
	</div>
<?php if ($event['event_status'] != events_config::$event_status['EVENT_STATUS_CLOSE']):?>
	<div class="form_block black_border margin_t_b_5" style="text-align:center">
	<?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_SOLUTION']):?>		
		<input type=button  id="open_again" class="sub_btn" value="重新打开" />
	<?php endif; ?>
		<input type=button  id="close_btn" class="sub_btn" value="确认关闭" />
	<?php if ($event['event_status'] == events_config::$event_status['EVENT_STATUS_CREATE']):?>
		<input type=button id="append_desc" class="sub_btn" value="追加描述" />
	<?php endif; ?>
	</div>
<?php endif;?>
</div>
<div id="closeBox" style="display:hidden"></div>
<div class="form_block black_border margin_t_b_5" id="append_desc_txt" style="margin-left:10px;display:none;">
	<div class="textarea_item">
		<label>描述/理由</label>
		<textarea name="append_desc"></textarea>
	</div>
	<div class="clear_both"></div>
		<div id="uploaded_file_info"  class="uploaded_file_info" style="padding-left:80px;clear:both;">
			<div id="fsUploadProgress" ></div>
		</div>
		<div class="clear_both"></div>
	<div class="upload_item">
		<label>附件</label>
		<span id="upload_btn"> </span> <input id="btnCancel" type="button" value="cancel" style="display:none;" />
	</div>
	<div class="clear_both"></div>
	<div style="text-align:center">
		<input type="submit" class="sub_btn" id="appendDescBtn" value="提交" />
	</div>
</div>
</body>
</html>
<script type="text/javascript">
$(function(){
	var dialogOpts = {
			modal: false,
			bgiframe: false,
			autoOpen: false,
			height: 230,
			width: 300,
			draggable: true,
			resizeable: true,
			title: '关闭事件',
			open: function() {
				$("#closeBox").load("<?php echo base_url()?>incident/loadCloseForm",{id:"<?=$eventId?>"});
			},
			close: function() {
				$("#closeBox").dialog("destroy");
			}
		};
	$("#close_btn").click(function(){
		$.ajax({
			url: "<?=base_url()?>incident/eventDetail",
			dataType: 'json',
			type: 'post',
			data: { event_id: "<?=$eventId?>" },
			success: function(ret) {
				if (!ret.success) {
					alert(ret.msg);
					return false;
				} else if (ret.event_status == "<?=events_config::$event_status['EVENT_STATUS_CLOSE']?>") {
					alert("事件已被关闭，不能重复关闭");
					return false;
				} else {
					$("#closeBox").dialog(dialogOpts);
					$("#closeBox").dialog("open");
				}
			}
		});
	});

	$("#open_again").click(function(){
		var eventId	= <?php echo $eventId;?>;
		var url	= "<?=base_url()?>incident/openagain";
		$.ajax({
			url: url,
			dataType: 'json',
			type: 'post',
			data: {eventId: eventId},
			success: function(ret) {
				alert(ret.msg);				
				if (ret.status)
					window.location.href = window.location.href;
			}
		})
	});
	/**
	$("#closeEventSubmit").live('click',function(){
		//提交关闭表单内容
		$("#closeBox").dialog("close");
	});
	$("#closeEventCancel").live('click',function(){

		$("#closeBox").dialog("close");
	});
	**/
	$("#closeEventSubmit").live('click',function(){
		var url = '<?=base_url()?>incident/close_event/event_id/<?=$eventId?>/';
		$.ajax({
			data: { event_closereason: $("#close_reason").val() },
			dataType: 'json',
			url: url,
			type: 'post',
			success: function(ret) {
				alert(ret.msg);
				if (ret.success) {
					$("#closeBox").dialog("close");
				} else {
					alert(ret.msg);
				}
			}
		});
	});

	$("#closeEventCancel").live('click',function(){
		$("#closeBox").dialog("close");
	});
	$("#event_category").change(function() {
		var url = "/incident/getSubclass";
		var event_category	= $(this).val();
		var option_type		= 'event_category';

		$.ajax({
			url: url,
			dataType: 'json',
			data: { event_category: event_category, option_type:option_type, s:Math.random() },
			type: 'post',
			success: function(ret) {
				var html = '';
				for(var o in ret) {
					html	+= '<option value="'+ret[o].option_id+'">'+ret[o].option_name+'</option>';
				}
				if (html != '')
				{
					$("#event_subclass").html(html);
				}
			}
		});
	});
	$("#append_desc").click(function() {
		$.ajax({
			url: "<?=base_url()?>incident/eventDetail",
			dataType: 'json',
			type: 'post',
			data: { event_id: "<?=$eventId?>" },
			success: function(ret) {
				if (!ret.success) {
					alert(ret.msg);
					return false;
				} else if (ret.event_status == "<?=events_config::$event_status['EVENT_STATUS_CLOSE']?>") {
					alert("事件已被关闭，不能再追加描述");
					return false;
				} else {
					$("textarea[name=append_desc]").val('');
					$("#append_desc_txt").toggle("display:block;");
				}
			}
		});
	});

	//提交追加描述
	$("#appendDescBtn").click(function(){
		var appendDesc = $("textarea[name=append_desc]").val();
		var url = "<?php echo base_url()?>incident/appendDesc";
		$.ajax({
			url: url,
			dataType:'json',
			data: { appendDesc:appendDesc,eventId:<?php echo intval($eventId)?>, s:Math.random() },
			type: 'post',
			success: function(ret) {
				if(ret.status)
				{
					window.location.href=window.location.href;
					/**
					$("textarea[name=event_desc]").text($("textarea[name=event_desc]").val()+ret.msg);
					$("#append_desc_txt").toggle("display:block;");
					$("#uploaded_file_info > .file_info").children(".del_attach").remove();
					$("#old_uploaded_file_info").append($("#uploaded_file_info").children(".file_info"));
					$("#uploaded_file_info").children(".file_info").remove();
					**/
				} else {
					alert(ret.msg);
				}
			}
		});
	});
	var swfu;
	var settings = {
			flash_url : "<?=base_url()?>media/flash/swfupload.swf",
			upload_url: "<?=base_url()?>upload/uploadAttachment/eventId/<?php echo $eventId;?>",
			post_params: {"PHPSESSID" : "<?php echo session_id(); ?>"},
			custom_settings : {
				progressTarget : "fsUploadProgress",
				cancelButtonId : "btnCancel",
				base_url:"<?=base_url()?>",
				uploadedFileInfoDiv:"uploaded_file_info"
			},
			debug: false,
			// Button settings
			button_image_url: "<?=base_url()?>media/images/upload_btn.gif"
		};
		swfu = new SWFUpload($.extend(settings,defaultSetting));
		$(".del_attach").live('click',function(){
			var divObj = $(this);
			$.get('<?php echo base_url()?>upload/delAttachment/aid/'+divObj.attr('aid'),function(data){
				if(data=='success')
				{
					divObj.parent().fadeOut();
				}
			});
		})
})

</script>
